package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiSubsidyApplicationTownPayment;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标平台_镇街支付明细表 映射层。
 *
 * @author 11987
 * @since 2025-07-06
 */
public interface LindiSubsidyApplicationTownPaymentMapper extends BaseMapper<LindiSubsidyApplicationTownPayment>{

    /**
     * 根据镇街支付明细ID查询镇街支付明细
     *
     * @param subsidyApplicationTownPaymentId 镇街支付明细ID
     * @return 镇街支付明细
     */
    default LindiSubsidyApplicationTownPayment selectSubsidyApplicationTownPaymentBySubsidyApplicationTownPaymentId(Long subsidyApplicationTownPaymentId){
        return selectOneByQuery(QueryWrapper.create().eq(
                LindiSubsidyApplicationTownPayment::getSubsidyApplicationTownPaymentId
                , subsidyApplicationTownPaymentId));
    }

    /**
     * 根据支付通知ID查询镇街支付明细列表
     *
     * @param subsidyApplicationPayNoticeId 支付通知ID
     * @return 镇街支付明细列表
     */
    default List<LindiSubsidyApplicationTownPayment> selectTownPaymentListBySubsidyApplicationPayNoticeId(Long subsidyApplicationPayNoticeId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationPayNoticeId
                        , subsidyApplicationPayNoticeId)
                .orderBy(LindiSubsidyApplicationTownPayment::getCreateTime, false));
    }

    /**
     * 根据镇街支付明细ID删除镇街支付明细
     *
     * @param subsidyApplicationTownPaymentId 镇街支付明细ID
     * @return 删除行数
     */
    default int deleteSubsidyApplicationTownPaymentBySubsidyApplicationTownPaymentId(Long subsidyApplicationTownPaymentId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationTownPaymentId
                        , subsidyApplicationTownPaymentId));
    }

    /**
     * 根据支付通知ID删除镇街支付明细
     *
     * @param subsidyApplicationPayNoticeId 支付通知ID
     * @return 删除行数
     */
    default int deleteBySubsidyApplicationPayNoticeId(Long subsidyApplicationPayNoticeId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationPayNoticeId
                        , subsidyApplicationPayNoticeId));
    }

    /**
     * 根据补贴申请支付通知ID查询镇街支付明细列表
     *
     * @param subsidyApplicationPayNoticeId 补贴申请支付通知ID
     * @return 镇街支付明细列表
     */
    default List<LindiSubsidyApplicationTownPayment>
    selectSubsidyApplicationTownPaymentListBySubsidyApplicationPayNoticeId(
            Long subsidyApplicationPayNoticeId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationPayNoticeId
                        , subsidyApplicationPayNoticeId)
                .orderBy(LindiSubsidyApplicationTownPayment::getTotalAmount
                        , false));
    }

    /**
     * 根据补贴申请支付通知ID删除镇街支付明细
     *
     * @param subsidyApplicationPayNoticeId 补贴申请支付通知ID
     * @return 删除行数
     */
    default int deleteSubsidyApplicationTownPaymentBySubsidyApplicationPayNoticeId(Long subsidyApplicationPayNoticeId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationPayNoticeId
                        , subsidyApplicationPayNoticeId));
    }

    /**
     * 根据补贴申请ID查询镇街支付明细列表
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 镇街支付明细列表
     */
    default List<LindiSubsidyApplicationTownPayment> selectTownPaymentListBySubsidyApplicationId(Long subsidyApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationId
                        , subsidyApplicationId)
                .orderBy(LindiSubsidyApplicationTownPayment::getCreateTime, false));
    }

    /**
     * 根据补贴申请ID删除镇街支付明细
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 删除行数
     */
    default int deleteBySubsidyApplicationId(Long subsidyApplicationId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationTownPayment::getSubsidyApplicationId
                        , subsidyApplicationId));
    }
}
